/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * Paint a dummy axis on dynamic layer while dragging an axis
 * @author: jin Chen 
 * @date: Jun 10, 2003
 * @version: $VERSION$
 */
package edu.psu.geovista.app.pcp.plot.layer.operation;

import edu.psu.geovista.app.plot.axis.YAxis;

import java.awt.*;

public class PreviewAxisOp extends BasicLayerOp{

    private YAxis axis;

    private Point location; //where to display previewed axis on the dynamic layer



    Rectangle paintRegoin;

    public PreviewAxisOp() {
        location=new Point();
    }

    public void paint(Graphics g) {
        Graphics2D g2d=(Graphics2D)g;
        //System.out.println("PreviewAxisOp paint()");
        int activeSize=axis.getActiveSize() ;

        int x=location.x ;
        //Point al=axis.getLocation(); //axis's location
        int y=axis.getLocation().y; //axis's location

        Rectangle rect=axis.getFooter().getOutLine() ;

        g2d.setColor(this.color );
        g2d.drawLine(x, y, x,y+activeSize);

        g.drawRect(x-rect.width/2,y+activeSize+YAxis.FOOTER_PAD ,rect.width,rect.height );
        //this.setPaintRegoin(x-AxisLayer.AXIS_GAP/2,0,AxisLayer.AXIS_GAP,AxisLayer.AX)
     }

    private  void setPaintRegoin(int x, int y, int w, int h) {
        if (this.paintRegoin ==null){
             Rectangle pr=new Rectangle(x,y,w,h);
            this.paintRegoin = pr;
        }
        this.paintRegoin.setBounds(x,y,w,h);
    }

    public void setLocation(double x, double y) {
        this.location.setLocation(x,y);

    }

    public void setAxis(YAxis axis) {
        this.axis = axis;
    }


    public void reset() {
         this.setAxis(null);
         this.setLocation(0,0);
    }
}
